Performance improvements, and make possible to compile with -DNDEBUG