Merge fixes for Issue #83

I have tested this SQL script on updated database.