-add: memwatch
-change: extracted most part out into a function