fixed undefined var and testcases