refactored client ip detection