Cleaned up some sql/code