cleaning up some sql query stuff