optimize detecting avatar image logic