bugfixes and perlcritic fixes