final version (without visualization)