add finally to avoid resource leak