Refactor code and enforce robustness | Capital One Interview Question