fix bugs and close idle connections