Cleaned up the code And many optimization changes.