fixed errors, simplified code