Added ActiveRecord extension and improve error handling