moving onerror to the right place