Lift some helpers to the top-level and make the code a bit more clean.