fixed crucial bugs