Improved readability of the code

Did some testing, found no issues after the changes