Applying various fixes from a fork of the project.