Move core implementation to impl/, add missing includes