some code layout improvements in js