putting detect ball in separate function