Refactoring and code cleanup
Fix ball not switching properly