Resource cleanup now done using goto
Length now checked at all places.