Refactor to use more instance variables; Better logging