Working on a little refactoring and bug fixes