division is done into right pieces but code is a mess