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 `detect` over `find`.