Major sanitization of code but not complete yet.