malloc and free added, and mostly done. needs cleanup and testing