added scala impl