Fixed a lot bugs