tweaks to db schema and improved the error handling