Added error tracking and other fixes