fixed collision by using a function from the internet and modifiying it