Fix socket crash due to picky function arrangement