Fixed bugs throughout