improve ball generating code