Extract errorbox code to a method