refactor code for reusability