turning binary tree functions to templates