changed return handling to use goto