DB logging and error handling and logging fixed