Code clean-up and added some documentation here and there.