Changes to fix and optimize database code. Also minor UI chnages for usability.