code clean up and refactor for adding records