refactored addLocalFile logic a bit to reduce duplicate code