improved javascript functionality