Rewrite activestate functionality