Use map instead of explicit loop when writing scripts