Implement more sound and fix window serialization.