refactor testing using RequireJS and fix bugs