Refactor the autoloader to make it more flexible