Rewrite complete loader into a recursive form

missing the materials