Some checks to avoid exceptions when writting