making some sql queries better and outputting a bit more info