Got rid of nested queries