Task code and variable refactoring