created array in map function
updated comments
corrected while loop in map function