Made things more modular so it's easier to switch between CPU and CUDA mode.