little refactor and logical bugfix