DB query fixes and gui tweaks