fixes a bug that undefined is not a function; adds more test cases; #1