Added lot of comments and fixed some styling.

Also added licenses

Change-Id: I04e790cea577163785519418ccc6fe6c3cefaafd