Add comments and little refactoring