Fixed bug in SQL, expanded code comments.