modify active window algorithm, resolves #106.