Added comments and algorithm