added edge cases for leaf and non-leaf nodes in Insert