little refactoring, it's still so ugly...