The code now close all SQL connections after used. Added some comments.