Fixed more memory bugs.
Moving input sanitation functions to separate files