fix typo and order functions definitions as the order they were called.