Fixed #119, #237 and #243 

Some mysql ordering and a javascript fix.

#119  #237  #243