Fixed some possible bugs