logic done, may need some comments for ecb cut and paste