Several bug fixes.
Temporary macro to simplify testing.
Bug fixes.