added an improved spin detection algorithm