Refactoring and tidying

This started as a branch trying to apply East Oriented code principles, but due to the current structure of the code I couldn't find anywhere to start and just ended up with a few unrelated improvements.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.