Improvements to Cuda KPM
Clean up and generalize KPM