a little refactored