complete refactor code