simplified and fortified js code