rewrite border collision for flexibility and accuracy