Changed popup algorithm