1.implemented db 2.improved error handling