re-write query processor to be more readable; support reversed range lookup queries
fix several mishandled buffer boundary check in files