Refactor Log and make command parsing even robuster