Reorganized and added memory allocation code.
Merge pull request #19 from kiLLeen/reorganize

Reorganization