refactor testing codes