tweaked jquery to improve functionality