fixing incorrect direction handling for rewrites