Fixed some bugs, made the scripts more extensible