Added comments and fixed some style issues