improved memlib execution, cleanup