Adding $2 base target name argument and refactoring existing code.