More bug fixes based on unit tests, etc.
Bug fixes/minor additions+global header file