added conditionals to make the code compatible with older versions of twisted as well