Fixed some mistakes and bugs