Twisted: refactored code