SQ9WTF - Second PR with changes mentioned in comments.

4725d38999a6c72de3eec5670977807c8ecc34cb 45a6eb1999f4db52319d74f44cd3a8a4f72711d8 11e11fc23ff7150ba5336bf44cbf0738e126f4af f0d7182999f0e2f72df0cc94fa13f0f26cfb8045 - github's diff can't show it nicely in the summary of the request, but here you have split of ee5690a4880509cd91e59270f85e3cbb96357468.