change a function to return value instead of storing value,
improve some loops,
remove unneeded sprite code, name sprite flash variable