changed error handling
Added database stuff