refactor the functionality