improved functionalization of steps, removed redundant variables from functions