partial refactor code