Add support for nested schemas

Refactor/rebase from #23