added cleanup code to db
various bug fixes
updated dir permissions