Fixed casting in write statements