Fixed unclosed cursor error