Implement shell loading mechanism and other fixes

See commit messages for details.