rewrite for gui usage