Moving write outside of else statement. I had put it there to debug in CLion.