code refactoring  - memory usage improvemenrt