Fixed return code

Return code is now checked and returned