Refactored the code agai