workin on algorithm by de Pina