Massive refactor of the codes.