Asserts and memory allocation fix.