Cleaned up ptree code