Modified query so it works in a cleaner way