Fix loop bug.
Add missing require.
Indent code.
Add date in erros.