refactor A0V flattening related code