Is this what you meant to do here? ++ operator is often frowned upon (certainly JSLint doesn't like it). Can we just increment the line before with "attachedTo = attachedTo + 1". Nice and clear.