Refactored to remove flip in backward