Naive scala implementation.