refactor target and file handling