Taking some stuff from @picandocodigo.