refs #8: small code refactor
refs #8: handled list depth better