Moved JS to dedicated code file.
Tweaked ordering logic.