added insert method with error handling