Code changes required by code review

This commit integrates all the suggestions raised so far, apart from one of them (the only one I replied to).