Fixed #119 and #243

Some mysql ordering and a javascript fix.