Fixed nesting; added test cases of nesting