fix a bug in alpha conversion
implement flattening