Added comments and formatted flow