Making javascript more generic