Port changes from core

Fixing tests and Makefile.PL in the process.