diff --git a/PG-PuReMD/configure.ac b/PG-PuReMD/configure.ac
index 7694620e54adaa01f4e9f9c8e70ca9816412b8ee..0edf0a24995cdf940c383177e87aae35e7e69787 100644
--- a/PG-PuReMD/configure.ac
+++ b/PG-PuReMD/configure.ac
@@ -27,7 +27,7 @@ AC_LANG([C])
 # Checks for programs.
 AC_PROG_CC([icc gcc clang cc])
 AC_PROG_CPP
-CFLAGS="$sav_CFLAGS"
+CFLAGS="${sav_CFLAGS}"
 
 AC_CONFIG_SRCDIR([src/torsion_angles.h])
 AC_CONFIG_HEADERS([src/config.h])
diff --git a/PuReMD/Makefile.am b/PuReMD/Makefile.am
index 809f3f0ca43c9c06dae8dabf13d57b778af2ff71..192ad0e9a1457c9e781fb94c941ead49eb54c1c2 100644
--- a/PuReMD/Makefile.am
+++ b/PuReMD/Makefile.am
@@ -1,7 +1,5 @@
 ACLOCAL_AMFLAGS = -I ../m4
 
-AM_CFLAGS = -Wall -O3 -funroll-loops -fstrict-aliasing #-finline-functions -finline-limit=15 -qhot
-
 bin_PROGRAMS = bin/puremd
 bin_puremd_SOURCES = src/allocate.c src/basic_comm.c src/ffield.c src/grid.c src/list.c src/lookup.c \
       src/io_tools.c src/reset_tools.c src/restart.c src/random.c src/tool_box.c src/traj.c \
@@ -18,5 +16,5 @@ include_HEADERS = src/reax_defs.h src/reax_types.h \
       src/bonds.h src/valence_angles.h src/hydrogen_bonds.h src/torsion_angles.h src/nonbonded.h src/forces.h \
       src/integrate.h src/init_md.h
 
-bin_puremd_CFLAGS = $(AM_CFLAGS) $(MPI_CFLAGS)
-bin_puremd_LDFLAGS = $(AM_LDFLAGS) $(MPI_LDFLAGS)
+bin_puremd_CFLAGS = $(AM_CFLAGS) $(MPI_CFLAGS) $(CFLAGS)
+bin_puremd_LDADD = $(AM_LDADD) $(MPI_LIBS) $(LDADD)
diff --git a/PuReMD/aclocal.m4 b/PuReMD/aclocal.m4
index 90f53cebe3fa0d0bbe5e05636b1e76997e5d30a2..82e03ac5980fdccb1702420a3fd77fc5c1be70d6 100644
--- a/PuReMD/aclocal.m4
+++ b/PuReMD/aclocal.m4
@@ -1,6 +1,6 @@
-# generated automatically by aclocal 1.15 -*- Autoconf -*-
+# generated automatically by aclocal 1.15.1 -*- Autoconf -*-
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -20,7 +20,7 @@ You have another version of autoconf.  It may work, but is not guaranteed to.
 If you have problems, you may need to regenerate the build system entirely.
 To do so, use the procedure documented by the package, typically 'autoreconf'.])])
 
-# Copyright (C) 2002-2014 Free Software Foundation, Inc.
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -35,7 +35,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION],
 [am__api_version='1.15'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 dnl require some minimum version.  Point them to the right macro.
-m4_if([$1], [1.15], [],
+m4_if([$1], [1.15.1], [],
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
 ])
 
@@ -51,14 +51,14 @@ m4_define([_AM_AUTOCONF_VERSION], [])
 # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
 # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
 AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.15])dnl
+[AM_AUTOMAKE_VERSION([1.15.1])dnl
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
 
 # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -110,7 +110,7 @@ am_aux_dir=`cd "$ac_aux_dir" && pwd`
 
 # AM_CONDITIONAL                                            -*- Autoconf -*-
 
-# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -141,7 +141,7 @@ AC_CONFIG_COMMANDS_PRE(
 Usually this means the macro was only invoked conditionally.]])
 fi])])
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -332,7 +332,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl
 
 # Generate code to set up dependency tracking.              -*- Autoconf -*-
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -408,7 +408,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
 
 # Do all the work for Automake.                             -*- Autoconf -*-
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -605,7 +605,7 @@ for _am_header in $config_headers :; do
 done
 echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -626,7 +626,7 @@ if test x"${install_sh+set}" != xset; then
 fi
 AC_SUBST([install_sh])])
 
-# Copyright (C) 2003-2014 Free Software Foundation, Inc.
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -647,7 +647,7 @@ AC_SUBST([am__leading_dot])])
 
 # Check to see how 'make' treats includes.	            -*- Autoconf -*-
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -697,7 +697,7 @@ rm -f confinc confmf
 
 # Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
 
-# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -736,7 +736,7 @@ fi
 
 # Helper functions for option handling.                     -*- Autoconf -*-
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -765,7 +765,7 @@ AC_DEFUN([_AM_SET_OPTIONS],
 AC_DEFUN([_AM_IF_OPTION],
 [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -812,7 +812,7 @@ AC_LANG_POP([C])])
 # For backward compatibility.
 AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -831,7 +831,7 @@ AC_DEFUN([AM_RUN_LOG],
 
 # Check to make sure that the build environment is sane.    -*- Autoconf -*-
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -912,7 +912,7 @@ AC_CONFIG_COMMANDS_PRE(
 rm -f conftest.file
 ])
 
-# Copyright (C) 2009-2014 Free Software Foundation, Inc.
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -972,7 +972,7 @@ AC_SUBST([AM_BACKSLASH])dnl
 _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
 ])
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -1000,7 +1000,7 @@ fi
 INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 AC_SUBST([INSTALL_STRIP_PROGRAM])])
 
-# Copyright (C) 2006-2014 Free Software Foundation, Inc.
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -1019,7 +1019,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
 
 # Check how to create a tarball.                            -*- Autoconf -*-
 
-# Copyright (C) 2004-2014 Free Software Foundation, Inc.
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -1151,3 +1151,4 @@ AC_SUBST([am__untar])
 ]) # _AM_PROG_TAR
 
 m4_include([../m4/acx_mpi.m4])
+m4_include([../m4/ax_compiler_vendor.m4])
diff --git a/PuReMD/configure.ac b/PuReMD/configure.ac
index 3df96c97ed2a807d88584a74297525fed8b8bec7..0168249747115f2cd2ce99926f61a21c7d179a4c 100644
--- a/PuReMD/configure.ac
+++ b/PuReMD/configure.ac
@@ -4,6 +4,8 @@
 AC_PREREQ([2.69])
 
 AC_INIT([PuReMD], [1.0], [ohearnku@msu.edu hma@msu.edu])
+# Do not allow AC_PROG_CC to set CFLAGS (this line must be after AC_INIT but before AC_PROG_CC)
+sav_CFLAGS="${CFLAGS}"
 : ${CFLAGS=""}
 AM_INIT_AUTOMAKE([1.15 subdir-objects -Wall -Werror foreign])
 # Enable silent build rules by default.
@@ -13,53 +15,21 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])], [AC_SUBST([AM_DEFAULT_VERB
 
 AC_CONFIG_MACRO_DIR([../m4])
 
-AC_LANG([C])
-
-AC_CONFIG_SRCDIR([src/torsion_angles.h])
-AC_CONFIG_HEADERS([src/config.h])
-
 # Headline formatter
 AC_DEFUN([CONFIGURE_HEADLINE],
 [
         echo; echo "+++ $1 +++"
 ])
 
-# Check for LAPACKE
-AC_CHECK_HEADERS([mkl.h], [MKL_FOUND_HEADERS="yes"])
-if test "x${MKL_FOUND_HEADERS}" = "xyes"
-then
-    AC_SEARCH_LIBS([LAPACKE_dgels], [mkl_intel_ilp64],
-                   [MKL_FOUND_LIBS="yes"], [MKL_FOUND_LIBS="no"], 
-                   [-lmkl_sequential -lmkl_core -lpthread -lm -ldl])
-    AS_IF([test "x${MKL_FOUND_LIBS}" != "xyes"],
-          [AC_MSG_ERROR([Unable to find MKL LAPACKE library.])])
-    LIBS="${LIBS} -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl"
-    AC_DEFINE([HAVE_LAPACKE_MKL], [1], [Define to 1 if you have MKL LAPACKE support enabled.])
-else
-    AC_CHECK_HEADERS([lapacke.h], [LAPACKE_FOUND_HEADERS="yes"])
-    if test "x${LAPACKE_FOUND_HEADERS}" = "xyes"
-    then
-        AC_SEARCH_LIBS([LAPACKE_dgels], [lapacke],
-                       [LAPACKE_FOUND_LIBS="yes"], [LAPACKE_FOUND_LIBS="no"],
-                       [-llapack])
-        AS_IF([test "x${LAPACKE_FOUND_LIBS}" != "xyes"],
-              [AC_MSG_ERROR([Unable to find LAPACKE library.])])
-        LIBS="${LIBS} -llapack"
-        AC_DEFINE([HAVE_LAPACKE], [1], [Define to 1 if you have LAPACKE support enabled.])
-    else
-        AC_MSG_WARN([
-  -----------------------------------------------
-   Unable to find LAPACKE on this system.
-   Disabling support for dependent methods.
-  -----------------------------------------------])
-    fi
-fi
-
-AC_LANG([C++])
+AC_LANG([C])
 
 # Checks for programs.
 AC_PROG_CC([cc icc gcc])
 AC_PROG_CPP
+CFLAGS="${sav_CFLAGS}"
+
+AC_CONFIG_SRCDIR([src/torsion_angles.h])
+AC_CONFIG_HEADERS([src/config.h])
 
 # Checks for libraries.
 AC_SEARCH_LIBS([exp], [m])
@@ -80,6 +50,21 @@ AC_FUNC_REALLOC
 AC_FUNC_STRTOD
 AC_CHECK_FUNCS([gettimeofday memset pow sqrt])
 
+# Check for compiler vendor
+AX_COMPILER_VENDOR
+if test "x${ax_cv_c_compiler_vendor}" = "xgnu"; then
+	if test "x${BUILD_DEBUG}" = "x"; then
+		CFLAGS="${CFLAGS} -Wall -O3 -funroll-loops"
+	else
+		CFLAGS="${CFLAGS} -Wall -O0 -g"
+	fi
+fi
+if test "x${ax_cv_c_compiler_vendor}" = "xintel"; then
+	if test "x${BUILD_DEBUG}" = "x"; then
+		CFLAGS="$CFLAGS -fast"
+	fi
+fi
+
 # Check for MPI support.
 CONFIGURE_HEADLINE([ MPI compiler ])
 ACX_MPI([], [AC_MSG_ERROR([could not find mpi library])])
@@ -87,62 +72,93 @@ AC_CHECK_PROG(MPIRUN, mpirun, mpirun)
 AC_SUBST(MPIRUN)
 
 # try to find if we are using OpenMPI / MPICH by looking inside mpi.h
-sav_CC="$CC"
-sav_CFLAGS="$CFLAGS"
-CC="$MPICC"
-CFLAGS="$CFLAGS"
+sav_CC="${CC}"
+sav_CFLAGS="${CFLAGS}"
+CC="${MPICC}"
+CFLAGS="${CFLAGS}"
 AC_CHECK_DECL([OPEN_MPI], [mpi_vendor="OpenMPI"],
 	     [], [#include "mpi.h"])
+# MPICH v2
 AC_CHECK_DECL([MPICH2], [mpi_vendor="MPICH2"],
 	     [], [#include "mpi.h"])
+# MPICH v3
 AC_CHECK_DECL([MPICH_VERSION], [mpi_vendor="MPICH3"],
 	     [], [#include "mpi.h"])
-CC="$sav_CC"
-CFLAGS="$sav_CFLAGS"
+CC="${sav_CC}"
+CFLAGS="${sav_CFLAGS}"
 
-#
-# try to set MPI_CFLAGS and MPI_LDFLAGS
-#
+# try to set MPI_CFLAGS and MPI_LIBS
 MPI_CFLAGS=
-MPI_LDFLAGS=
-if test "x$mpi_vendor" = "xOpenMPI"
+MPI_LIBS=
+if test "x${mpi_vendor}" = "xOpenMPI"
 then 
-	MPI_CFLAGS=`$MPICC --showme:compile`
-	MPI_LDFLAGS=`$MPICC --showme:link`
+	MPI_CFLAGS=`${MPICC} --showme:compile`
+	MPI_LIBS=`${MPICC} --showme:link`
 	AC_MSG_NOTICE([OpenMPI found])
-	AC_MSG_NOTICE([MPI_CFLAGS=$MPI_CFLAGS])
-	AC_MSG_NOTICE([MPI_LDFLAGS=$MPI_LDFLAGS])
-elif test "x$mpi_vendor" = "xMPICH2" || test "x$mpi_vendor" = "xMPICH3"
+	AC_MSG_NOTICE([MPI_CFLAGS=${MPI_CFLAGS}])
+	AC_MSG_NOTICE([MPI_LIBS=${MPI_LIBS}])
+elif test "x${mpi_vendor}" = "xMPICH2" || test "x${mpi_vendor}" = "xMPICH3"
 then
 	# build MPI_CFLAGS
-	tmp=`$MPICC -compile-info | awk '{$1=""; print $0 }'`
+	tmp=`${MPICC} -compile-info | awk '{$1=""; print $0 }'`
 	MPI_CFLAGS=
 	for i in $tmp
 	do 
 		case $i in 
 			-[[DIUbi]]*)
-				MPI_CFLAGS="$MPI_CFLAGS $i"
+				MPI_CFLAGS="${MPI_CFLAGS} ${i}"
 				;;
 		esac
 	done
-	# build MPI_LDFLAGS
-	tmp=`$MPICC -link-info | awk '{$1=""; print $0 }'`
+	# build MPI_LIBS
+	tmp=`${MPICC} -link-info | awk '{$1=""; print $0 }'`
 	for i in $tmp
 	do 
 		case $i in 
 			[[\\/]]*.a | ?:[[\\/]]*.a | -[[lLRu]]* | -Wl* )
-				MPI_LDFLAGS="$MPI_LDFLAGS $i"
+				MPI_LIBS="${MPI_LIBS} ${i}"
 				;;
 		esac
 	done
 	AC_MSG_NOTICE([MPICH found])
-	AC_MSG_NOTICE([MPI_CFLAGS=$MPI_CFLAGS])
-	AC_MSG_NOTICE([MPI_LDFLAGS=$MPI_LDFLAGS])
+	AC_MSG_NOTICE([MPI_CFLAGS=${MPI_CFLAGS}])
+	AC_MSG_NOTICE([MPI_LIBS=${MPI_LIBS}])
 else
 	AC_MSG_WARN([Neither OpenMPI and MPICH have been recognized...])
 fi
 AC_SUBST(MPI_CFLAGS)
-AC_SUBST(MPI_LDFLAGS)
+AC_SUBST(MPI_LIBS)
+
+# Check for LAPACKE
+AC_CHECK_HEADERS([mkl.h], [MKL_FOUND_HEADERS="yes"])
+if test "x${MKL_FOUND_HEADERS}" = "xyes"
+then
+	AC_SEARCH_LIBS([LAPACKE_dgels], [mkl_intel_ilp64],
+		       [MKL_FOUND_LIBS="yes"], [MKL_FOUND_LIBS="no"],
+		       [-lmkl_sequential -lmkl_core -lpthread -lm -ldl])
+	AS_IF([test "x${MKL_FOUND_LIBS}" != "xyes"],
+	      [AC_MSG_ERROR([Unable to find MKL LAPACKE library.])])
+	LIBS="${LIBS} -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl"
+	AC_DEFINE([HAVE_LAPACKE_MKL], [1], [Define to 1 if you have MKL LAPACKE support enabled.])
+else
+	AC_CHECK_HEADERS([lapacke.h], [LAPACKE_FOUND_HEADERS="yes"])
+	if test "x${LAPACKE_FOUND_HEADERS}" = "xyes"
+	then
+		AC_SEARCH_LIBS([LAPACKE_dgels], [lapacke],
+			       [LAPACKE_FOUND_LIBS="yes"], [LAPACKE_FOUND_LIBS="no"],
+			       [-llapack])
+		AS_IF([test "x${LAPACKE_FOUND_LIBS}" != "xyes"],
+		      [AC_MSG_ERROR([Unable to find LAPACKE library.])])
+		LIBS="${LIBS} -llapack"
+		AC_DEFINE([HAVE_LAPACKE], [1], [Define to 1 if you have LAPACKE support enabled.])
+	else
+		AC_MSG_WARN([
+  -----------------------------------------------
+   Unable to find LAPACKE on this system.
+   Disabling support for dependent methods.
+  -----------------------------------------------])
+	fi
+fi
 
 AC_CONFIG_FILES([Makefile])
 
diff --git a/PuReMD/src/reax_types.h b/PuReMD/src/reax_types.h
index 81b55c64091e54aa1d5ed1f92b1396d3379fdfbc..30a3dacade764cf854b834a06bb5c4d8b1b34597 100644
--- a/PuReMD/src/reax_types.h
+++ b/PuReMD/src/reax_types.h
@@ -22,6 +22,11 @@
 #ifndef __REAX_TYPES_H_
 #define __REAX_TYPES_H_
 
+#if (defined(HAVE_CONFIG_H) && !defined(__CONFIG_H_))
+  #define __CONFIG_H_
+  #include "config.h"
+#endif
+
 #include <ctype.h>
 #include <math.h>
 #include <mpi.h>