Refactoring of memory plugin

Improve command handling and code refactoring