Fix bug with list flattening