implemented query close and open?. added better close check for connection