First working version (for CPU)