Moved some code out of the core.