refactor the code further