fill in main algorithm and start writing tests to fix/verify it