improved whole script