Added write() wrapper and refined comparison test.