Added support for nested dictionaries

Should now be able to cope with nested dictionaries. The changes are relatively small,
but hurt my head as functions call themselves.