Update flatten method to handle associative arrays