formatted code and added documentation