adding comments, more robust checking for remote IP, adding missing import