Refactoring and cleaning up TWI.