SQL query fixes and other miscellaneous.