Adding flatten script