refactor, add tests, update readme.

Should now produce expected results on all tests.
I was going back and forth on the flattening. But, there reason I did is that even though this looks like an edge case, it happen sometimes in realistic use cases. e.g. when templates are expanded and return an array:

```js
src: ['<%= foo %>, '*.js']
```
I'm not opposed to removing. perhaps we can re-add if the issue crops up.