fixes on the query that was breaking it horribly