MOB-1235: Added SQL error handling; Proper foreign keys