Refactored the code again