Improved SQL close