diff --git a/source/KKRnano/source/Makefile b/source/KKRnano/source/Makefile
index cfb93cf13f35bcaa914c562fb0481c5edb9415e8..759599018256f3db8ce4be073e6212a3ee2950a6 100644
--- a/source/KKRnano/source/Makefile
+++ b/source/KKRnano/source/Makefile
@@ -26,6 +26,10 @@ FC90FLAGS =
 FCFLAGS =
 PPFLAGS =
 PPFLAGS += -D USE_VOROWEIGHTS
+ifeq ($(TYPE),debug)
+	PPFLAGS += -D DEBUG
+endif
+# PPFLAGS += -D NDEBUG
 
 # PPFLAGS += -D BENCHMARK_tfQMR
 # PPFLAGS += -D EXPORT_tfQMR_PROBLEM
@@ -33,7 +37,6 @@ PPFLAGS += -D USE_VOROWEIGHTS
 # PPFLAGS += -D TRANSPOSE_TO_ROW_MAJOR
 ### TRANSPOSE_TO_ROW_MAJOR seems to work, however, there was a bug in col_norms about the non-linearity of DZNRM2, so we have to see which references went wrong
 #PPFLAGS += -D SUPERCELL_ELECTROSTATICS=8
-#  -D NDEBUG
 LDFLAGS =
 
 # ========= IFF Workstations ============
@@ -42,9 +45,9 @@ ifeq ($(PLATFORM),ifort)
 	FC = mpiifort -warn all
 	FC90 = mpiifort -warn all
 	# -module <path> specifies where to put .mod files
-  	ifeq ($(SMP),openmp)
- 		FCFLAGS += -qopenmp
-        endif
+	ifeq ($(SMP),openmp)
+		FCFLAGS += -qopenmp
+	endif
 	FCFLAGS += -module $(BUILDDIR)
 	FCFLAGS += -I $(BUILDDIR)
 	# PPFLAGS += -D TASKLOCAL_FILES
@@ -62,7 +65,7 @@ ifeq ($(PLATFORM),ifort)
 		FCFLAGS += -O0 -g -check bounds -traceback -debug all -check all
 		PPFLAGS += -D USE_MTRADII -D USE_OLD_MESH -D NOLOGGING
  	else ifeq ($(TYPE),voronoi_mesh)
-		FCFLAGS += -O2 
+		FCFLAGS += -O2
 		PPFLAGS += -D NOLOGGING -D USE_OLD_MESH
  	else ifeq ($(TYPE),voronoi_mesh_debug)
 		FCFLAGS += -O0 -g -check bounds -traceback -debug all -check all -fpe1
@@ -73,7 +76,6 @@ ifeq ($(PLATFORM),ifort)
 	else ifeq ($(TYPE),voronoi_mesh_print_mtradii)
 		FCFLAGS += -O0 -g
 		PPFLAGS += -D NOLOGGING -D USE_OLD_MESH -D PRINT_MTRADII
-
 	else
 		FCFLAGS += -O2 
 		PPFLAGS += -D NOLOGGING
diff --git a/source/KKRnano/source/RefCluster_mod.F90 b/source/KKRnano/source/RefCluster_mod.F90
index 1199b1157178340a69a0f03d38649215881e3e1f..67ee595f19f29a4d68875eff9d487d71be18be5d 100644
--- a/source/KKRnano/source/RefCluster_mod.F90
+++ b/source/KKRnano/source/RefCluster_mod.F90
@@ -166,7 +166,7 @@ module RefCluster_mod
 
 #ifdef DEBUG  
     write(*,'(a,2(i0,a),9999(" ",i0))') 'for atom #',source_atom_index,'  indn0(1:',self%numn0,') =',self%indn0(:)
-    write(*,'(a,3F16.12)') 'rcls(:,1) = ',rcls(1:3,1)
+    write(*,'(a,3F16.12)') 'rcls(:,1) = ',self%rcls(1:3,1)
 #endif
     ! todo: display some statistics
 #ifdef DEBUG
diff --git a/source/KKRnano/source/madelung/MadelungCalculator_mod.F90 b/source/KKRnano/source/madelung/MadelungCalculator_mod.F90
index 7eeafff7e4410a7c73d0a01f88c6b23e3cbe17d2..da8839117391f246ce23c1195b0ea09d64268c98 100644
--- a/source/KKRnano/source/madelung/MadelungCalculator_mod.F90
+++ b/source/KKRnano/source/madelung/MadelungCalculator_mod.F90
@@ -886,7 +886,7 @@ module MadelungCalculator_mod
     det = determinant3x3_r(a)
     if(det == 0.) then
 #ifdef DEBUG
-      if(o>0) write(o,'(9A)') sym,' invert3x3: determinant = 0.'
+      write(*,'(9A)') ' invert3x3: determinant = 0.'
 #endif
       inverse = 0.
       return
diff --git a/source/KKRnano/source/parallel/KKRnano_Comm_mod.F90 b/source/KKRnano/source/parallel/KKRnano_Comm_mod.F90
index fbe5f4e675d570674d16886078ed881aeee83aeb..76d54bfa3004c6e0b19bcd9a06489ef4740b1396 100644
--- a/source/KKRnano/source/parallel/KKRnano_Comm_mod.F90
+++ b/source/KKRnano/source/parallel/KKRnano_Comm_mod.F90
@@ -79,6 +79,7 @@ module KKRnano_Comm_mod
   !> Set the number of OpenMP threads to nthrds.
   subroutine setKKRnanoNumThreads(nthrds)
     integer, intent(in) :: nthrds
+!$  external :: OMP_SET_NUM_THREADS
     if (nthrds > 0) then
       !$ call OMP_SET_NUM_THREADS(NTHRDS)
     endif ! nthrds > 0