Formatted code, improved some comments