Added error handling for all WriteElement calls

Shit may happen at very strange moment, better to handle error everywhere