Added ErrorException and cleaned up the database extension