IT WORKS! Now fixing the logic