fixed bad join query and properly check for IP in use