added some error handling and removed mongoid