Free resources on error
Remove duplicate branch