first version without split and double and probably with bugs finished