refactor code for simplicity