Major Code Refactoring, and some reformatting.