Added comments and changed coding style