fixed typo and made render function easier to understand