Major Code formatting. Updated version