code clean-up and commenting