moved the function to its own class (looks a bit less horible and now I can reuse this code properly)