Added comments and updates to the problematic function.