using map rather then while