bugfix and integration into script