Major refactoring. Seperated CUDA specific code into inline .cuh files.

Added sampling functions.