added two scala implementations