some bug fixes and tests for flatten transform (WIP)