Fixed save to db error when no record returned, small bug fixes