Improved .val() function