diff --git a/src/BaseGrid.h b/src/BaseGrid.h
index 73d48f1cddd04c76b516dec8601bfc8013b5f52c..eee5cf71ef4cadc6c6b14c2b6c3ed5110935b277 100644
--- a/src/BaseGrid.h
+++ b/src/BaseGrid.h
@@ -19,10 +19,10 @@
 #include <cstdio>
 #include <cstdlib>
 #include <ctime>
-#include <cuda.h>
+// #include <cuda.h>
 
 
-using namespace std;
+// using namespace std;
 
 #define STRLEN 512
 
diff --git a/src/BrownianParticleType.h b/src/BrownianParticleType.h
index a3c5f487bab05cccb87ea2718162f960f6c15c36..b6ed4eccbf814ccf81c953ad9a9f9f1007f77751 100644
--- a/src/BrownianParticleType.h
+++ b/src/BrownianParticleType.h
@@ -13,7 +13,6 @@
 #include "Reservoir.h"
 #include "BaseGrid.h"
 #include "CellDecomposition.h"
-#include "BaseGrid.h"
 
 // Stores particle type's potential grid and other information
 class BrownianParticleType {
diff --git a/src/ComputeForce.h b/src/ComputeForce.h
index 66d6e75356fa46d22dab40e9f9a89e9768ed7b93..cbe2be8f64013696adcf676b1c8599c66b065633 100644
--- a/src/ComputeForce.h
+++ b/src/ComputeForce.h
@@ -24,7 +24,7 @@
 #include "TabulatedDihedral.h"
 
 #include <cstdio>
-#include <cuda.h>
+// #include <cuda_runtime.h>
 #include <thrust/transform_reduce.h>	// thrust::reduce
 #include <thrust/functional.h>				// thrust::plus
 
diff --git a/src/DcdWriter.h b/src/DcdWriter.h
index f2c0f61aaf03ed579262df59f47c496c0ebe634a..d5ab57d2933eab11315383df196c82edbb094865 100644
--- a/src/DcdWriter.h
+++ b/src/DcdWriter.h
@@ -21,7 +21,7 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
-using namespace std;
+// using namespace std;
 
 #define NFILE_POS (off_t) 8
 #define NPRIV_POS (off_t) 12
diff --git a/src/FlowForce.h b/src/FlowForce.h
index 870aca005af4f316151d0b2abe401d06eedd0889..8ffe930af173b908201ec9de7fe046d310e0b768 100644
--- a/src/FlowForce.h
+++ b/src/FlowForce.h
@@ -5,7 +5,7 @@
 
 #include <cmath>
 #include "useful.h"
-using namespace std;
+// using namespace std;
 
 class FlowForce {
 public:
diff --git a/src/GrandBrownTown.h b/src/GrandBrownTown.h
index 006ae8ad1dfde892ec3c1580ff0c5a555a8ab993..981066472431021233f61b58400c4cc030f6d0bc 100644
--- a/src/GrandBrownTown.h
+++ b/src/GrandBrownTown.h
@@ -48,7 +48,7 @@
 
 //#include "analyticForce.h"
 
-using namespace std;
+// using namespace std;
 
 // #define FORCEGRIDOFF
 
diff --git a/src/Makefile b/src/Makefile
index b8da44fa4a15fa477e274a2a363fe2e03d0b5d4b..f359fd0962d8ba25d45f90877c3ea21a3f07c510 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,7 +2,6 @@
 include ./findcudalib.mk
 INCLUDE = $(CUDA_PATH)/include
 
-NV_FLAGS += v
 ifeq ($(dbg),1)
 	CC_FLAGS += -g -O0
 	NV_FLAGS += -g -G
@@ -11,7 +10,8 @@ else
 	EX_FLAGS = -O3 -m$(OS_SIZE)
 endif
 
-CC_FLAGS += -Wall -Wno-write-strings -I$(INCLUDE) -std=c++0x -pedantic
+CC_FLAGS += -I$(CUDA_PATH)/include
+# CC_FLAGS += -Wall -Wno-write-strings -std=c++0x -pedantic
 NV_FLAGS += -lineinfo
 
 ifneq ($(DARWIN),)
@@ -22,10 +22,16 @@ endif
 
 # NV_FLAGS += -ftz=true			# TODO: test if this preserves accurate simulation
 
+$(info $(NVCC))
+
 ## Find valid compute capabilities for this machine
 SMS ?= 20 30 35 37 50 52 60
 $(info Testing CUDA toolkit with compute capabilities SMS='$(SMS)')
-SMS := $(shell for sm in $(SMS); do $(NVCC) cuda-test.c -arch=sm_$$sm &> /dev/null && echo $$sm; done)
+SMS := $(shell for sm in $(SMS); do $(NVCC) cuda-test.c -arch=sm_$$sm -o /dev/null &> /dev/null && echo $$sm; done)
+
+ifeq (,$(SMS))
+    $(error nvcc ($(NVCC)) failed with all tested compute capabilities.)
+endif
 
 SMPTXS ?= $(lastword $(sort $(SMS)))
 $(info Building SASS code for SMS='$(SMS)' and PTX code for '$(SMPTXS)')
diff --git a/src/RandomCUDA.cu b/src/RandomCUDA.cu
index 670028049604c71c96f5c874086c4dd0bbde71fc..0a92583d8795df2add7bf9c7bdaca4bec3c8306a 100644
--- a/src/RandomCUDA.cu
+++ b/src/RandomCUDA.cu
@@ -79,7 +79,7 @@ void Random::reorder(int a[], int n) {
 		unsigned int j = i + (integer() % (n-i));
 		if ( j == i )
 			continue;
-		swap<int>(a[i], a[j]);
+		std::swap<int>(a[i], a[j]);
 		const int tmp = a[j];
 		a[j] = a[i];
 		a[i] = tmp;
diff --git a/src/RigidBodyGrid.h b/src/RigidBodyGrid.h
index 2c46b4ff1331f57a8d04cc4b21e79e124bb438ef..96a5d03b466dd3c60708ce65f85005bce81bd574 100644
--- a/src/RigidBodyGrid.h
+++ b/src/RigidBodyGrid.h
@@ -22,7 +22,7 @@
 #include <ctime>
 #include <cuda.h>
 
-using namespace std;
+// using namespace std;
 
 #define STRLEN 512
 
diff --git a/src/Scatter.h b/src/Scatter.h
index b6bee35afb77ce73e68d44c1b0abb7905dbc205d..3347fcc6fbe3d99e60a369946ec8b96406e953e8 100644
--- a/src/Scatter.h
+++ b/src/Scatter.h
@@ -8,7 +8,7 @@
 #include <cstdlib>
 #include <cstdio>
 #include "useful.h"
-using namespace std;
+// using namespace std;
 
 class Scatter {
 public:
diff --git a/src/arbd.cpp b/src/arbd.cpp
index ebd1eea1ef829a64608635826564be134351aa06..32bcccda9a257765acd9933fda17b33774b783fd 100644
--- a/src/arbd.cpp
+++ b/src/arbd.cpp
@@ -9,7 +9,8 @@
 #include "Configuration.h"
 #include "GPUManager.h"
 
-using namespace std;
+// using namespace std;
+using std::max;
 
 const unsigned int kIMDPort = 71992;
 
diff --git a/src/findcudalib.mk b/src/findcudalib.mk
index 7c7884918917bba95538bae0fd3e0097fa269931..4694c946b5466539734bf91bfd21628b12079b26 100644
--- a/src/findcudalib.mk
+++ b/src/findcudalib.mk
@@ -36,13 +36,11 @@
 
 ## Find Location of most recent CUDA Toolkit
 ifeq (,$(CUDA_PATH))
-	CUDA_PATH := $(shell echo $(wildcard /usr/local/cuda*) | tr ' ' '\n' | sort -Vr | head -n1)
+    CUDA_PATH := $(shell echo $(wildcard /usr/local/cuda*) | tail -n1)
     ifeq (,$(CUDA_PATH))
-        $(info ERROR: Could not CUDA_PATH. Please pass as follows: $(MAKE) CUDA_PATH=/path/to/cuda)
-        exit
-    else 
-        $(info Using CUDA_PATH=$(CUDA_PATH))
+        $(error Could not CUDA_PATH. Please pass as follows: $(MAKE) CUDA_PATH=/path/to/cuda)
     endif
+    $(info Using CUDA_PATH=$(CUDA_PATH))
 endif
 
 # OS Name (Linux or Darwin)
@@ -91,7 +89,7 @@ else
     ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
         CC = $(CLANG)
 		CC_FLAGS += -stdlib=libstdc++
-		NV_FLAGS += -Xcompiler -arch -Xcompiler x86_64
+		NV_FLAGS += -Xcompiler -arch -Xcompiler x86_64 -Xcompiler -stdlib=libstdc++
     endif
 endif
 NVCC ?= $(CUDA_PATH)/bin/nvcc -ccbin $(CC)
diff --git a/src/gridSampleDef.c b/src/gridSampleDef.c
index e5082f2556f35b0888b647000f3db4854f957514..c89bec557e8bd8f56856ad70c3d8bdd455eb4723 100644
--- a/src/gridSampleDef.c
+++ b/src/gridSampleDef.c
@@ -8,7 +8,7 @@
 #include "BaseGrid.h"
 #include "OverlordGrid.h"
 
-using namespace std;
+//using namespace std;
 
 int main(int argc, char* argv[]) {
   if ( argc != 4 ) {
diff --git a/src/gridSampleFlow.c b/src/gridSampleFlow.c
index b7a94d3ac55424ef8d4ceeb3fd142bde3d9c3671..f5f2896fbb9fc9e8e5e81efa817bda32dd373fd6 100644
--- a/src/gridSampleFlow.c
+++ b/src/gridSampleFlow.c
@@ -8,7 +8,7 @@
 #include "BaseGrid.h"
 #include "FlowForce.h"
 
-using namespace std;
+// using namespace std;
 
 int main(int argc, char* argv[]) {
   if ( argc != 4 ) {
diff --git a/src/useful.h b/src/useful.h
index 73f1b7b9735d6f0a9f67b6325a11e1ccdf8b14a9..1618b9a463b4132658ea1a2a5fffc49591e63daf 100644
--- a/src/useful.h
+++ b/src/useful.h
@@ -16,9 +16,9 @@
 #include <cstring>
 #include <cstdio>
 #include <cstdlib>
-#include <cuda.h>
+//#include <cuda_runtime.h>
 
-using namespace std;
+// using namespace std;
 
 bool isReal(char c);