insert return and refactor code