First implementation. Comments to be improved. Solution seems to be correct.