Corrected most bugs