improve the robustness and performance when fixing jQuery .val() function, plus better comments and code readability