large structural update. lots of semantic changes and readability improvements