added header memory_monitor
added some more logic, still the code is broken