adding detect and draw_rects functions