script bugfixes, improvements