changed javascript handling to be more robust, but also more verbose..
less padding