use lapply instead of for loop, this speed up much