Fixing small logic problem