Let's just split that up into a function instead of copy pasta'ing it

Signed-off-by: Toon Schoenmakers <nighteyes1993@gmail.com>