moved prying code to a function