[OPTIMIZATION] Some optimization in the head command. See #298