PAHMA-1010: Minor refactoring, and delete closed connections when the max has been reached.