Revert "Revert "a seperate function for this stuff""

This reverts commit 1199b8ae11b1e0c955b9aa8ecd68696e5859d659.