changed check_invariants() to not execute if NDEBUG is defined