final version
fixed minor scope bug with add-type