changes from Psiphon's code