fixed formatPoints function and scoping on query function

the query function is unusable without these fixes