added custom assert to check memory consistency