Added exception handling to fix bug and fixed typos.