fix - change order of function definitions such that the function is known when called
fix warning about shadowed variables .. and some other  unimportant ones