Reorganize structure and solve not defined variables