Logic fix, todo: cleanup
Added children support
Refactored a bit