Fixed error with closing connection