Refactor data block handling.

This should fix various bugs related to multiple scenes in the same
file and other reuses of data blocks.