cleanup and error fixing