Some logic was wrong. Corrected.