Used map and lambda functions instead of loops