Refactored for my app ;-)