db cleanup and minor bug fixes