critical bugfix, thanks to cfastie for reporting