cleaned up and formatted code