refactor: various variable redefinitions and nesting object structure