refactor loading controller to be more flexible