Cleaned the code a bit.
Added test on mapping state.
Typo in the NDEBUG macro.