Fast refactoring

Very ugly code has become a bit better.