Code cleanup and optimizations. Converted Databasedat to singleton.