Fix classes declaration
Close connections properly