Updated code and fixed typo.