rewrite some minor code

I've rewritten the code that checks for the port that Timbl is running on.

Please test it before committing the merge, I haven't tested it myself because I don't have corpus data and timbl running. Basically the code should do exactly the same as it did, but is more readable and modular.