added nesting + some minor improvements