Added more tests and fixed nesting