Fix 'require' error. Some code refactor.