Edited readability and added in appropriate comments