added comments and little refact