Refactor habit code.