Implementet CMATWEANN in (ugly) scala