changed order of 2 lines to allow display error message before code breaks