Movement and ball detection fixed and improved. More thoroughly commented.