Refactor browser detect method