Working, but not pretty, impl of CPU