rewrite select script