Adding insert_motive and refactoring code