removed FLATTEN call and cleaned up output