bugfixes and a little refactoring