Refactor test cases. And added 'time' function