added collision checking