toAdmin function and JavaScript fixes