Fix some errors in autoload and cleaned up misc code