fixed errors and added comments