cleaning up code for error message and spinner