refactor and enhance process and memory management