Bugfix: It was not possible to run a file in a package
bug fixes around importing.

This code is in need of refactoring, but it can wait until after the plugin work is all done
minor refactoring of core.py