Fixed bugs after some testing