refactor to use cursor
introduce tree
append getNext method
append add method for array attributes
get sort from query string