Use lapply instead of for