cleaned up and commented the code