Fix some typos/replace loop with sapply