Refactor

Replace `for` by `reduce` and `map`. Delete some commented code segments.