refactor and simplify loader