Use E_FAIL instead of -1 and clean up