[CLEANUP] Licence & commenting

 - added licence header
 - added more comments
 - cleaned some code