Refactored code to be able compile in C89 to support compiling from Visual Studio 2003.