add additional memory_usage check
externalize stop conditions
unittests