Clean code

Change nested array indexing to pointers, add some comments to functions