implemented tree structure and added tests