Refactoring monta_relacoes.php