Clean Up Flatten Function

#### Resolves #46