Refactor variables and add comments