Vastly simplify JS script