fixed formatPoints function and scoping on query function

this fixes the query function