   urlBehavior ||= noughts.state.UrlBehavior.PUSH_URL
   Session.set("state", newState)
   newScreen = noughts.state.stateMap[newState]
-  newScreen.enterState.apply(newScreen, _.rest(arguments))
+  # Arguments should be [urlBehavior, args[2], args[3], etc]
+  newArgs = [urlBehavior].concat(_.toArray(arguments).slice(2))
+  newScreen.enterState.apply(newScreen, newArgs)
 
 # What a new state should do to the browser URL when entered.
 noughts.state.UrlBehavior =

              noughts.state.changeState(noughts.state.FACEBOOK_INVITE)
        , {redirect_uri: noughts.appUrl + "facebookInvite"}

  init: ->
    $(".nNewGameMenuCloseButton").on "click", =>
      if noughts.state.hasPreviousState()
        noughts.state.back()
      else
        noughts.state.changeState(noughts.state.INITIAL_PROMO)

    $(".nUrlInviteButton").on("click",
        _.bind(this.handleUrlInviteButtonClick_, this))
    $(".nFacebookInviteButton").on("click",
        _.bind(this.handleFacebookInviteButtonClick_, this))

  onEnterState: (urlBehavior) ->
    noughts.state.updateUrl("/new", urlBehavior)
    $(".nMain").children().hide()
    $(".nScreenNewGame").show()

noughts.FacebookInviteMenu = noughts.Screen.extend
  onEnterState: (urlBehavior) ->
    # TODO(dthurn): Log user into facebook here if they aren't yet.
    noughts.state.updateUrl("/facebookInvite", urlBehavior)
    $(".nMain").children().hide()
    $(".nScreenFacebookInvite").show()
    # Scaling tends to mess up on this screen, especially e.g. when the
    # keyboard pops up on mobile.
    Session.set("disableScaling", true)

# The initial promo for non-players that explains what's going on.
noughts.InitialPromo = me.ScreenObject.extend
  init: ->
    $(".nNewGameButton").on "click", =>
      noughts.state.changeState(noughts.state.NEW_GAME_MENU)

  onResetEvent: (urlBehavior) ->
    noughts.state.updateUrl("/", urlBehavior)
    $(".nMain").children().hide()
    $(".nScreenInitialPromo").show()

# The main screen used for actually playing the game.
noughts.PlayScreen = me.ScreenObject.extend
  init: ->
    $(".nSubmitButton").on "click", ->
      Meteor.call "submitCurrentAction", Session.get("gameId"), (err) ->
        if err then throw err
        noughts.displayToast("Move submitted")
    $(".nUndoButton").on "click", ->
      Meteor.call("undoCommand", Session.get("gameId"))
    $(".nRedoButton").on "click", ->
      Meteor.call("redoCommand", Session.get("gameId"))

  # Enables/disables the three move control buttons (undo, redo, submit) based
  # on whether or not they are currently applicable.

# Possibly modifies the current browser URL to the to provided path, based on
# the behavior requested in the 'urlBehavior' parameter (a
# noughts.state.UrlBehavior).
noughts.state.updateUrl = (urlBehavior, path) ->
  # TODO(dthurn): No point in doing this if we're inside the Facebook iframe
  if urlBehavior == noughts.state.UrlBehavior.PUSH_URL
    window.history.pushState({}, "", path)
  else if urlBehavior == noughts.state.UrlBehavior.REPLACE_URL
