Fixed incorrect message size calculation upon write