fixed ball collision bug, added envelope collision check, code optimization