Refactor code and enhances it