Fix mkdir, refactor some more