Working version of task B. Bad results though.