Added valid and inorder checks