adds some important assertions and exception throwing.