Fixed checking & handling of return code