Refactoring to rearrange some code as well as clean up

Code for creation of query is moved to ternProvider... ternProvider now
creates the query and uses the query internally... ternManager used to
create the query and then sent down to ternProvider. Also cleaned up
some of the interfaces