added correctness test, added another implementation