commented and refatored code fixed errors