move code for show/hide errors into functions