fixed many bugs with array, made refinement more efficient, refactored query.jl, fixed bug in pre_bfs which was failing when p=0 or p=1