Refactored the code :D