refactor and add insert method
add tests for insert function