Fixed a bug in sort script which should have used generic db name