Fixed bugs

The previous version didn't work at all (lol)