change first and last function