working on refactoring code, removing dynamic alloc