Fixed important bugs