less nesting, a little smarter