Fix cross-platform bugs