fix error handling & dup check