Finished basic functions

Finished most of the basic functions and fixed some of the memory
problems.