Added isBalanced function