refactored ptree code into multiple files