big refactor to avoid opening to many files