Fix acceptedConnection memory problem by moving it to a higher scope