Refactoring things to use dynamic memory allocation.