Fixed some fatal bugs