more refactoring nesting, it's all kinda fragile right now, time for cleanup
more cleanup of nesting