reshuffling js code

Signed-off-by: Mikolaj Szabo <savingprivateblue@gmail.com>