trying to refactor code