Fix database sorting issues

closes #55