Added comments and fixed some formatting