wrote collision logic