Refactored to be C89 compliant for building with Visual Studio 2008.