Refactor code to remove instance variable calls