Fixed some major and minor bugs