remove unused code
handle errors in own function