Corrected preorder postorder function