Refactor multiple calls to main; use list & map