Need help with some logic in my sketch.