Made structural changes to @celon's bug fix.
Search and replaced variables with old C++ style uppercased variables to C style lowercase.
Search and replaced incorrect source headers.