refactoring with functions, plus footprint plots