added flatten + media check. fixes #127 fixes #131