hacky code to extract patches