stuck the patch stuff in a function