Improved code readability and added comments