Use port 40000 for REST server and try the next 20 ports if listening fails. Removed unused code.