fixing short circuit algorithm