refactor bbox code part 1