Refactoring http://www.bradgoodman.com/thermostat/