Applying filtering early to have less later on
Factoring out two map calls into one
Don't create extra promise when not needed
Prepare internal promise chain for each file

instead of calling map multiple times