Fix polling and thread issues