first attempt to refactor code