some memory optimizations and code refactoring