code reorganized. first test in main.