Added comments for code clarity