Semantic correction on the rebased branch.

Please ignore the previous pull request as it is no longer valid

Part 3

(this is on the rebased branch)

Please check the TODO lines