improved box detection