refactor code works