Code clean-up and commenting