refactor generic loader