Added tree class and few helper functions