bugfixes, uses more variables