added error listener and made some cleanups