Fixed many shameful bugs. :(