I've refactored this in bd55525