made some minor changes and formatted some code