Refactoring ball code