taken from http://svn.code.sf.net/p/simplettsreader/code