refactored code from issue #45 (added insert method)