moved closing connections to util method as per code review notes