debug and a little refactor