Refactored code in binary search tree implementation