Generalized the loader code slightly