refactor some code to be clearer in copy-plugin