added a crappy scala implementation