Added a few changes and made code easier to read