Clean up and query fixes