Merge my master branch

As agreed, the commits are quite atomic and small. More to come.
Why move everything into the if statement? Makes everything less clear IMO.