Use defer instead of goto

Tests pass :)