If you put in an else block to go with the "if(write_button(...", it would be executed on the initial page load, but not after a successful save. It would be executed again on an unsuccessful save attempt (due to a field validation error), which may or may not be what you want.
count(fields)...