Warning: untested code; Changes to make code cuda5.0 compatible