Fixed loads of bugs, making variables scope limited