formatted code; added some documentation