Fixed some error issues regarding shutdown