added comments to the UCS method to explain how each line works