Added some documentation and cleaned some logic up.