Added comments and some minor modifications.