Fixed some bugs & useless code