Fixing branch cleanup and reset logic