fixed typo and improved code